def sum_of_number(n: int) -> int:
    if n < 10:
        return n
    else:
        sum = 0
        for i in str(n):
            sum += int(i)
        if sum > 9:
            return sum_of_number(sum)
        else:
            return sum

if __name__ == "__main__":
    n = int(input("自然数n："))
    print("最终的数字之和是：%d"%sum_of_number(n))